/*
 Navicat Premium Dump SQL

 Source Server         : docker
 Source Server Type    : MySQL
 Source Server Version : 80042 (8.0.42)
 Source Host           : localhost:3306
 Source Schema         : med_consultation_db

 Target Server Type    : MySQL
 Target Server Version : 80042 (8.0.42)
 File Encoding         : 65001

 Date: 13/08/2025 10:32:15
*/

SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;

-- ----------------------------
-- Table structure for consultation_evaluation
-- ----------------------------
DROP TABLE IF EXISTS `consultation_evaluation`;
CREATE TABLE `consultation_evaluation` (
  `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键',
  `session_id` bigint NOT NULL COMMENT '会话ID → consultation_session.id',
  `staff_id` bigint NOT NULL COMMENT '医生/医护人员ID',
  `patient_id` bigint NOT NULL COMMENT '患者ID（不做外键）',
  `rating` tinyint NOT NULL COMMENT '评分 1-5',
  `content` varchar(500) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT NULL COMMENT '文字评价（可空）',
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '评价时间',
  PRIMARY KEY (`id`),
  KEY `idx_session` (`session_id`),
  KEY `idx_staff` (`staff_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='问诊评价表';

-- ----------------------------
-- Records of consultation_evaluation
-- ----------------------------
BEGIN;
COMMIT;

-- ----------------------------
-- Table structure for consultation_session
-- ----------------------------
DROP TABLE IF EXISTS `consultation_session`;
CREATE TABLE `consultation_session` (
  `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键',
  `user_id` bigint NOT NULL COMMENT '用户ID（患者所属用户）',
  `type` tinyint NOT NULL COMMENT '来源类型：1 碎片 / 2 线上排班',
  `appointment_id` bigint DEFAULT NULL COMMENT '来源预约ID（仅type=2）',
  `order_id` bigint DEFAULT NULL COMMENT '来源订单ID（仅type=1）',
  `staff_id` bigint NOT NULL COMMENT '医生ID',
  `patient_id` bigint NOT NULL COMMENT '患者ID（不做外键）',
  `status` tinyint NOT NULL DEFAULT '0' COMMENT '0未开始/1进行中/2已结束/3已关闭',
  `started_at` datetime DEFAULT NULL COMMENT '会话开始时间',
  `ended_at` datetime DEFAULT NULL COMMENT '会话结束时间',
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  PRIMARY KEY (`id`),
  KEY `idx_type` (`type`),
  KEY `idx_status` (`status`),
  KEY `idx_staff` (`staff_id`),
  KEY `idx_patient` (`patient_id`),
  KEY `idx_user` (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='问诊会话表';

-- ----------------------------
-- Records of consultation_session
-- ----------------------------
BEGIN;
COMMIT;

-- ----------------------------
-- Table structure for encounter
-- ----------------------------
DROP TABLE IF EXISTS `encounter`;
CREATE TABLE `encounter` (
  `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键',
  `session_id` bigint NOT NULL COMMENT '会话ID → consultation_session.id',
  `staff_id` bigint NOT NULL COMMENT '医生/医护人员ID',
  `patient_id` bigint NOT NULL COMMENT '患者ID（不做外键）',
  `chief_complaint` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT NULL COMMENT '主诉',
  `diagnosis` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT NULL COMMENT '诊断',
  `advice` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT NULL COMMENT '医嘱',
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  PRIMARY KEY (`id`),
  KEY `idx_session` (`session_id`),
  KEY `idx_staff` (`staff_id`),
  KEY `idx_patient` (`patient_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='就诊/诊间记录表';

-- ----------------------------
-- Records of encounter
-- ----------------------------
BEGIN;
COMMIT;

SET FOREIGN_KEY_CHECKS = 1;
